# Vercel Build Validation

This guide explains how to use our build validation script with Vercel's "Ignored Build Step" feature to ensure proper localization file updates.

## Overview

When deploying to Vercel, it's important to ensure that all localization files are properly synchronized. We provide a build script that validates localization file changes and determines whether a deployment should proceed.

## Using the Ignored Build Step

In your Vercel project settings, you can use our validation script in the "Ignored Build Step" field. This will prevent unnecessary builds when localization files aren't properly synchronized.

Set the following in the "Ignored Build Step" field:
```bash
bash vercel-build.sh
```

**Note:** Make sure the script is in your repository's root directory or adjust the path accordingly.

## Build Script

The build script (`vercel-build.sh`) checks if changes to the source localization file (`en.json`) are properly reflected in other locale files:

```bash
#!/bin/bash

# Change these to your source paths
LOCALES_DIR="src/locales"
SOURCE_FILE="${LOCALES_DIR}/en.json"

# Check if there are any changes at all
if git diff HEAD^ HEAD --quiet; then
  echo "No changes detected. Skipping build."
  exit 0
fi

# Check if there are changes in source file
if git diff --name-only HEAD^ HEAD | grep -q "^${SOURCE_FILE}$"; then
  echo "Changes detected in ${SOURCE_FILE}"
  # Check if other files in source directory were also changed
  if git diff --name-only HEAD^ HEAD | grep -q "^${LOCALES_DIR}/[^/]*\.json$" | grep -v "^${SOURCE_FILE}$"; then
    echo "Other locale files were also changed. Proceeding with build..."
    exit 1
  else
    echo "${SOURCE_FILE} was changed but other locale files were not. Failing build."
    exit 0
  fi
else
    # If no changes in source file, proceed with build
    echo "No changes in ${SOURCE_FILE}. Proceeding with build..."
    exit 1
fi
```

## How It Works

The script follows Vercel's "Ignored Build Step" convention:

- Returns `exit 0`: Skip the build (when validation fails or no changes detected)
- Returns `exit 1`: Proceed with the build (when changes are valid)

The script performs these checks:

1. Detects if any changes were made in the current commit
2. If the source locale file (`en.json`) was modified:
   - Checks if other locale files were also updated
   - Prevents the build if only the source file was changed
3. Allows the build to proceed if:
   - No changes were made to the source file
   - Both source and other locale files were updated

## Important Notes

1. Vercel performs a shallow clone with `git clone --depth=10`, so the script will only have access to the last 10 commits
2. The script runs in the same directory as your project's "Root Directory" setting in Vercel
3. Make sure the script has executable permissions (`chmod +x vercel-build.sh`) before committing


For more information about setting up GitHub Actions for translation workflows, see our [GitHub Actions guide](./github-actions).
